package ui.base;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;


/**
 * Created by chenxunlin01 on 2017/10/13.
 */

public abstract class BaseActivity<T extends BaseController> extends AppCompatActivity {

    protected T controller;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        controller = createController();
        if(controller!=null){
            controller.doOnCreate(savedInstanceState);
        }
    }

    @Override
    protected void onPause() {
        if(controller!=null){
            controller.doOnPause();
        }
        super.onPause();
    }

    @Override
    protected void onResume() {
        super.onResume();
        if(controller!=null){
            controller.doOnResume();
        }
    }

    @Override
    protected void onDestroy() {
        if(controller!=null){
            controller.doOnDestroy();
        }
        super.onDestroy();
    }

    /**
     * 创建controller
     *
     * @return
     */
    protected abstract T createController();
}
